package top.zhangjianyong.blog.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseMapper;
import java.time.LocalDateTime;
import java.util.List;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import top.zhangjianyong.blog.entity.dto.BlogDTO;
import top.zhangjianyong.blog.entity.po.Blog;
import top.zhangjianyong.blog.params.blog.BlogPageParam;
import top.zhangjianyong.blog.params.blog.BlogTopListParam;

/**
 * 博客
 *
 * @author zhangjianyong
 * @since 2024/7/31 下午8:47
 */
public interface BlogMapper extends MPJBaseMapper<Blog> {
  Page<BlogDTO> portalPage(IPage<?> page, BlogPageParam param);

  List<BlogDTO> topList(BlogTopListParam param);

  @Select("select max(push_time) from blog where create_user =#{userId} and status = 1")
  LocalDateTime getLastBlogPushTime(Long userId);

  @Update("update blog set views =views+1 where id =#{blogId}")
  void addViews(Long blogId);

  @Update("update blog set likes =likes+1 where id =#{blogId}")
  void addLikes(Long blogId);

  List<BlogDTO> listPublished();
}
